package com.example.orderservice.listener;



import com.example.orderservice.domain.vo.pointVo;
import com.example.orderservice.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;


/**
 * 支付状态监听器
 * 监听支付成功消息，处理积分增加逻辑
 *
 * @author czwa
 */
@Component
@RequiredArgsConstructor
public class PayStatusListener {

    private final IOrderService orderService;

    /**
     * 监听支付成功队列，增加用户积分
     *
     * @param pointVo 包含用户ID和积分值的视图对象
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(
                    name = "point.success.queue",
                    durable = "true",
                    arguments = @Argument(name = "x-queue-mode", value = "lazy")
            ),
            exchange = @Exchange(name = "point.direct"),
            key = "point.success"
    ))
    public void addPoint(pointVo pointVo) {
        // 调用订单服务增加用户积分
        orderService.addPoint(pointVo);
    }
}